package com.yaolong.api.modules.gen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yaolong.commons.base2.BaseServiceImpl;
import com.yaolong.api.modules.gen.model.dto.TemplateDetailDto;
import com.yaolong.api.modules.gen.model.entity.TemplateFile;
import com.yaolong.api.modules.gen.dao.TemplateFileDao;
import com.yaolong.api.modules.gen.service.ITemplateFileService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 模板文件表 服务实现类
 * </p>
 *
 * @author yaolonga
 * @since 2022-12-30
 */
@Service
public class TemplateFileServiceImpl extends BaseServiceImpl<TemplateFileDao, TemplateFile> implements ITemplateFileService {
    @Override
    public IPage<TemplateDetailDto> getTemplateDetailsPage(int current, int size, TemplateDetailDto query) {
        Page<TemplateDetailDto> page = new Page<>(current, size);
        QueryWrapper<TemplateDetailDto> wrapper = new QueryWrapper<>();
        wrapper.eq(!ObjectUtils.isEmpty(query.getTemplateType()),"Template_Type",query.getTemplateType());
        wrapper.eq(!ObjectUtils.isEmpty(query.getTemplateGenType()),"Template_Gen_Type",query.getTemplateGenType());
        wrapper.eq(!ObjectUtils.isEmpty(query.getGroupId()),"Group_Id",query.getGroupId());
        return baseMapper.getTemplateDetailsPage(page, wrapper);
    }

    @Override
    public List<TemplateDetailDto> getTemplateDetailsList(TemplateDetailDto query) {
        QueryWrapper<TemplateDetailDto> wrapper = new QueryWrapper<>();
        wrapper.eq(!ObjectUtils.isEmpty(query.getTemplateType()),"Template_Type",query.getTemplateType());
        wrapper.eq(!ObjectUtils.isEmpty(query.getTemplateGenType()),"Template_Gen_Type",query.getTemplateGenType());
        wrapper.eq(!ObjectUtils.isEmpty(query.getGroupId()),"Group_Id",query.getGroupId());
        return baseMapper.getTemplateDetailsList(wrapper);
    }
}
